﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using StudentManage.Data;

namespace StudentManage.Web
{
    public partial class UC_MasterDrop : System.Web.UI.UserControl
    {
        public delegate void DropEventDelegate();
        public event DropEventDelegate SelectedChanging;

        public string SetValue
        {
            set { this.Drop_xy.SelectedValue = value;}
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack) return;

            List<xydm> xylist = xydm.All().ToList();
            this.Drop_xy.DataSource = xylist;
            this.Drop_xy.DataValueField = "XYDM";
            this.Drop_xy.DataTextField = "XYMC";
            this.Drop_xy.DataBind();

            if (Session["SelectedXYDM"] != null)
                this.Drop_xy.SelectedValue = Session["SelectedXYDM"].ToString();

            this.Drop_xy_SelectedIndexChanged(null, null);
        }

        protected void Drop_xy_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.Drop_xy.SelectedItem == null) return;
            Session["SelectedXYDM"] = this.Drop_xy.SelectedValue;

            if (SelectedChanging != null)
                SelectedChanging();
        }
    }
}